# -*- coding: utf-8 -*-

import pika  
import sys  
import json

parameters=pika.ConnectionParameters(  
			credentials=pika.PlainCredentials('guest', 'guest'),
        	host='127.0.0.1',
        	port=5672,
        	virtual_host='/test'
        )
connection = pika.BlockingConnection(parameters)

channel = connection.channel()  

exchange = 'tpq_batch-ex'
routing_key = 'tpq_batch'
message = json.dumps({'name':'test_py','age':12})

# 指定 java 解析类 '__TypeId__':'com.kuaihaowei.model.JsonMqTest'

properties = pika.BasicProperties(
	      		delivery_mode=2,
	      		content_type='application/json',
	      		headers={'__TypeId__':'com.kuaihaowei.model.JsonMqTest'}
           	)

channel.basic_publish(exchange=exchange,  
                      routing_key=routing_key,
                      properties=properties,
                      body=message)  

print "sent exchange : {}, routing_key : {}, message : {}".format(exchange, routing_key, message)  
connection.close()  